<template>
	<view class="pages">
		
		<headerMain
		:headerBg="'#ffffff'"
		@goBack="goBack" :backColor="'black'"
		:headerTitle="'评价列表'" :titleColor="'#000'"
		:heightTop="heightTop"
		/>
		
		<view class="comment">
			<view class="comment-tab">
				<view class="comment-tab__item" v-for="(item,index) in tabList" :key="index"
				@tap.stop="checkTabActive(item,index)">
				<uni-badge class="uni-badge-left-margin" :text="item.value" absolute="rightTop" :offset="[-5, 10]" size="small">
					<view class="name" :class="{'name--active' : tabActive == index}">{{item.name}}</view>
				</uni-badge>
				</view>
			</view>
			
			<!-- 列表 -->
			<view class="servicesBox">
				<view class="servicesBox-evaluate" v-if="arr.length > 0">
					<view class="servicesBox-evaluateList" v-for="(item,index) in arr" :key="index">
						<view class="avatar">
							<img src="@/static/public/wechat.png" alt="" />
						</view>
						<view class="wordBox">
							<view class="top">
								<view class="name">胖胖鱼</view>
								<view class="time">2024-12-24</view>
							</view>
							<view class="fraction">
								<img src="@/static/type/start.png" alt="" />
								<img src="@/static/type/start.png" alt="" />
								<img src="@/static/type/start.png" alt="" />
								<view class="fen">3分</view>
							</view>
							<view class="title">用户暂未评价</view>
							<view class="imageBox" v-if="index% 2 == 0">
								<view class="imageBox-box" v-for="(itemKey,indexKey) in 2" :key="indexKey">
									<img src="https://img14.360buyimg.com/n1/s450x450_jfs/t1/226875/3/22653/29461/668f53f0F2f50d2c1/f267d77b39cfc882.jpg" alt="" />
								</view>
							</view>
							<view class="imageBox" v-else>
								<view class="imageBox-box" v-if="tabActive == 1" v-for="(itemKey,indexKey) in 1" :key="indexKey">
									<img src="https://img14.360buyimg.com/n1/s450x450_jfs/t1/226875/3/22653/29461/668f53f0F2f50d2c1/f267d77b39cfc882.jpg" alt="" />
								</view>
								<view class="imageBox-box" v-else v-for="(itemKey,indexKey) in 4" :key="indexKey">
									<img src="https://img14.360buyimg.com/n1/s450x450_jfs/t1/226875/3/22653/29461/668f53f0F2f50d2c1/f267d77b39cfc882.jpg" alt="" />
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="initNoData" v-if="arr.length == 0">
					暂无记录
				</view>
			</view>
			
			<view class="initBtn" @tap.stop="openPopup()">发布评价</view>
			
		</view>
		
		<uni-popup ref="commentPopup" type="bottom" 
		 :animation="true" @change="changePopup($event,'commentPopup')">
			<view class="popupBox">
				<view class="popupBox-header">
					<view class="title">
						发布评价
					</view>
					<image @tap.stop="hidePopup('commentPopup')" class="close" src="/static/public/icon-clear.png" mode=""></image>
				</view>
				<view class="popupBox-box">
					<view class="top">
						<img class="avatar" src="@/static/public/wechat.png" alt="" />
						<view class="name">胖胖鱼</view>
					</view>
					<view class="fraction">
						<view class="describe">描述相符</view>
						<uni-rate :value="rateValue"
						 color="#bbb" active-color="#1afa29"
						@change="onChange"/>
						<!-- <img src="@/static/type/start.png" alt="" />
						<img src="@/static/type/start.png" alt="" />
						<img src="@/static/type/start.png" alt="" /> -->
					</view>
					<view class="inputBox">
						<textarea v-model="describe" placeholder="评价内容请写在这儿咯" cols="30" rows="10"></textarea>
						<!-- title="最多选择9张图片" -->
						<uni-file-picker limit="9" v-model="imageValue" 
						fileMediatype="image" 
						mode="grid" 
						@select="select" 
						@progress="progress" 
						@success="success" 
						@fail="fail" ></uni-file-picker>
					</view>
					<view class="initBtn" @tap.stop="release()">
						发布评价
					</view>
				</view>
			</view>
		</uni-popup>
		
	</view>
</template>

<script>
	export default {
		components: {
		}, 
		data() {
			return { 
				heightTop: 0,
				tabList: [
					{name: '全部',value : 0,},
					{name: '好评',value : 3,},
					{name: '中评',value : 2,},
					{name: '差评',value : 0,},
				],
				tabActive: 0,
				// value: 1,
				arr: [{},{},{},{},{}],
				describe: '',
				imageValue:[],
				rateValue: 0,
			}
		},
		onPageScroll(e) {
			this.heightTop = e.scrollTop;
		}, 
		onLoad() {
		},
		onShow() {
			// this.init();
			const timer = setInterval(() => {
				if (this.value >= 199) {
					clearInterval(timer)
					return
				}
				this.value++
			}, 10000)
		},
		methods: {
			init(){
			},
			
			release(){
				let that = this;
				if(Number(that.rateValue) == 0){
					console.log('请给描述相符打上对应的星星');
					uni.showToast({
						title: '请给描述相符打上对应的星星',
						icon: "none",
					})
					return
				}
				if(that.describe == ''){
					uni.showToast({
						title: '请填写评价内容',
						icon: "none",
					})
					return
				}
				if(that.imageValue.length == 0){
					uni.showToast({
						title: '请上传相关评价内容凭证',
						icon: "none",
					})
					return
				}
				setTimeout(()=>{
					uni.showToast({
						title: '发布评价成功',
						icon: "none",
					})
					this.rateValue = 0;
					that.describe == '';
					that.imageValue = [];
				},1500)
			},
			
			onChange(e) {
				let that = this;
				console.log('rate发生改变:' + JSON.stringify(e));
				that.rateValue = JSON.stringify(e).value;
			},
			
			// 获取上传状态
			select(e){
				console.log('选择文件：',e);
				let image = e.tempFilePaths;
				this.imageValue = image;
				console.log('凭证：',this.imageValue);
			},
			// 获取上传进度
			progress(e){
				console.log('上传进度：',e)
			},
			
			// 上传成功
			success(e){
				console.log('上传成功')
			},
			
			// 上传失败
			fail(e){
				console.log('上传失败：',e)
			},
			
			/* 弹出框公用 */
			openPopup(e){
				// 通过组件定义的ref调用uni-popup方法 ,如果传入参数 ，type 属性将失效 ，仅支持 ['top','left','bottom','right','center']
				this.$refs.commentPopup.open('popup');
				// this.$refs.commentPopup.open('bottom')
				// this.$refs[e].open();
			},
			hidePopup(e) {
				// this.$refs.popup.close()
				this.$refs[e].close();
			},
			changePopup(e) {
				console.log('popup ' + e.type + ' 状态', e.show);
			},
			
			checkTabActive(item,index){
				if(this.tabActive != index){
					this.tabActive = index;
					if(this.tabActive == 1){
						this.arr = [{},{},{}]
					}else if(this.tabActive == 2){
						this.arr = [{},{}]
					}else if(this.tabActive == 3){
						this.arr = []
					}else{
						this.arr = [{},{},{},{},{}]
					}
				}
			},
			
			clearData(keyName) {
				for (var key in this.$data) {
					if (key == keyName) {
						this.$data[key] = '';
					}
				}
			},
		}
	}
</script>

<style scoped lang="scss">
	.comment{
		&-tab{
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			align-items: center;
			background: #ffffff;
			padding: 0 20rpx;
			height: 75rpx;
			position: fixed;
			width: calc(100% - 40rpx);
			&__item{
				text-align: center;
				width: 25%;
				position: relative;
				.name{
					font-size: 28rpx;
					color: #999999;
					padding: 20rpx 0;
					&--active{
						font-size: 30rpx;
						color: #64c1ad;
						&:before{
							content: '';
							position: absolute;
							bottom: 0rpx;
							left: 0;right: 0;
							width: 55rpx;
							height: 6rpx;
							margin: auto;
							background: #64c1ad;
							border-radius: 10rpx;
						}
					}
				}
			}
		}
		.initBtn{
			width: calc(100% - 50rpx);
			position: fixed;
			bottom: 50rpx;
			left: 0;right: 0;
			// box-shadow: 0px 5rpx 5rpx 0rpx rgba(26, 250, 41, 0.6);
			box-shadow: 0px 5rpx 5rpx 0rpx rgba(153, 202,156, 0.6);
		}
	}
	
	.servicesBox{
		background: #ffffff;
		padding: 20rpx;
		// margin: 10px 0;
		height: calc(100vh - 75rpx - 88rpx - 40rpx);
		margin-top: 68rpx;
			&-evaluate{
				display: flex;
				flex-direction: column;
				justify-content: flex-start;
				align-items: center;
				margin: 20rpx 0 0;
			}
			&-evaluateList{
				display: flex;
				flex-direction: row;
				justify-content: flex-start;
				align-items: flex-start;
				width: 100%;
				border-bottom: 1px solid #f6f6f6;
				margin-bottom: 20rpx;
				.avatar{
					background: #f0f0f0;
					border-radius: 50%;
					width: 60rpx;
					height: 60rpx;
					margin-right: 20rpx;
					img{
						width: 100%;
						height: 100%;
					}
				}
				.wordBox{
					display: flex;
					flex-direction: column;
					justify-content: flex-start;
					align-items: flex-start;
					width: calc(100% - 80rpx);
					margin-bottom: 20rpx;
					.top{
						display: flex;
						flex-direction: row;
						justify-content: space-between;
						align-items: center;
						width: 100%;
						.name{
							font-size: 26rpx;
							color: #666666;
						}
						.time{
							font-size: 26rpx;
							color: #666666;
						}
					}
					.fraction{
						display: flex;
						flex-direction: row;
						justify-content: flex-start;
						align-items: center;
						margin: 10rpx 0;
						img{
							width: 40rpx;
							height: 40rpx;
							margin-right: 5rpx;
						}
						.fen{
							font-size: 28rpx;
							color: #1afa29;
							margin: 0 10rpx;
						}	
					}
					.title{
						font-size: 26rpx;
						color: #000000;
					}
					.imageBox{
						display: flex;
						flex-direction: row;
						justify-content: flex-start;
						align-items: center;
						flex-wrap: wrap;
						margin-top: 10rpx;
						width: 100%;
						&-box{
							width: 31.33%;
							height: 100%;
							margin-right: 2%;
							&:nth-last-child(1){
								margin-right: 0%;
							}
							img{
								width: 100%;
								height: 100%;
								border-radius: 20rpx;
							}
						}
					}
				}
			}
			
			
	}

	.popupBox{
		background: #ffffff;
		border-radius: 20rpx 20rpx 0 0;
		padding: 20rpx;
		&-header{
			position: relative;
			.title{
				text-align: center;
				// font-size: 20rpx;
			}
			.close{
				position: absolute;
				right: 0rpx;
				top: 0rpx;
				width: 35rpx;
				height: 35rpx;
			}
		}
		&-box{
			.top{
				display: flex;
				flex-direction: row;
				align-items: center;
				justify-content: flex-start;
				.avatar{
					background: #f0f0f0;
					border-radius: 50%;
					width: 60rpx;
					height: 60rpx;
					margin-right: 10rpx;
				}
				.name{
					font-size: 28rpx;
					color: #000000;
				}
			}
			.fraction{
				display: flex;
				flex-direction: row;
				align-items: center;
				justify-content: flex-start;
				margin: 10rpx 0;
				img{
					width: 40rpx;
					height: 40rpx;
					margin-right: 5rpx;
				}
				.describe{
					font-size: 26rpx;
					color: #666666;
					margin: 0 10rpx;
				}	
			}
			.inputBox{
				background: #f8f8f8;
				padding: 20rpx;
				margin: 20rpx 0;
				display: flex;
				flex-direction: column;
				justify-content: flex-start;
				align-items: flex-start;
				textarea{
					font-size: 28rpx;
					color: #000000;
					height: 120rpx;
				}
			}
			.initBtn{
				width: 60%;
			}
		}
	}

</style>